<script setup lang="ts">
import { onMounted } from 'vue'
import { ref } from 'vue'

// 1. 定义 ref
const pRef = ref(null)
// console.log(pRef.value)

// 3. onMounted 获取
onMounted(() => {
  // onMounted 中是最早可以获取到 dom 元素的生命周期函数
  // console.log(pRef.value)

  document.querySelector('p')

  // 非空断言 + as 类型强转
  ;(pRef.value! as HTMLParagraphElement).style.backgroundColor = 'pink'
})
</script>

<template>
  <div id="app">
    <!-- 2. 设置给 dom 元素 -->
    <!-- ref="xxx" xxx 需要和定义的状态变量同名 -->
    <p ref="pRef">隆江猪脚饭</p>
  </div>
</template>

<style>
* {
  margin: 0;
  padding: 0;
  list-style: none;
}

.news {
  display: flex;
  height: 120px;
  width: 600px;
  margin: 0 auto;
  padding: 20px 0;
  cursor: pointer;
}

.news .left {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-right: 10px;
}

.news .left .title {
  font-size: 20px;
}

.news .left .info {
  color: #999999;
}

.news .left .info span {
  margin-right: 20px;
}

.news .right {
  width: 160px;
  height: 120px;
}

.news .right img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
</style>
